# ------------------------------------------------------------------------------
# Python program using the library to interface with the arduino sketch above.
# ------------------------------------------------------------------------------

import PyCmdMessenger
import time
# Initialize an ArduinoBoard instance.  This is where you specify baud rate and
# serial timeout.  If you are using a non ATmega328 board, you might also need
# to set the data sizes (bytes for integers, longs, floats, and doubles).  
arduino = PyCmdMessenger.ArduinoBoard("COM14",baud_rate=9600)

# List of command names (and formats for their associated arguments). These must
# be in the same order as in the sketch.
commands = [["move_to","iii"],
            ["move_to_retult","s"]]

# Initialize the messenger
c = PyCmdMessenger.CmdMessenger(arduino,commands)

# Send
# c.send("who_are_you")
# # Receive. Should give ["my_name_is",["Bob"],TIME_RECIEVED]
# msg = c.receive()
# print(msg)

# Send with multiple parameters
# while True:
#     c.send("move_to",250,0,100)
#     msg = c.receive()

#     # should give ["sum_is",[5],TIME_RECEIVED]
#     print(msg)
#     # time.sleep(8)
#     c.send("move_to",250,0,10)
#     msg = c.receive()

#     # should give ["sum_is",[5],TIME_RECEIVED]
#     print(msg)
#     time.sleep(8)
#     break

while True:
    c.send("move_to",250,0,30)
    time.sleep(10)
    c.send("move_to",250,0,200)
    time.sleep(10)
# while True:
#     print("start")
#     for pos in range(30, 200):
#         print(pos)
#         c.send("move_to",250,0,pos)
#         msg = c.receive()
#         time.sleep(0.05)

#     for pos in reversed(range(30, 200)):
#         print(pos)
#         c.send("move_to",250,0,pos)
#         msg = c.receive()
#         time.sleep(0.05)